package io.renren.modules.oss.cos.controlller;


import io.renren.common.utils.Result;
import io.renren.modules.security.user.SecurityUser;
import io.renren.modules.security.user.UserDetail;
import io.renren.modules.oss.cos.service.OssOperateService;
import io.renren.modules.oss.cos.dto.FileUploadReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yun lang
 * @version 1.0
 * @description: OSS操作
 * @date 2024/11/6 09:15
 */
@RestController
@RequestMapping("/oss/operate")
@Tag(name = "登录接口")
@AllArgsConstructor
public class OssOperateController {
    private static final Logger logger = LoggerFactory.getLogger(OssOperateController.class);

    private final OssOperateService ossOperateService;

    @PostMapping("/uploadFile")
    @Operation(summary = "上传单个文件")
    public Result uploadFile(@ModelAttribute FileUploadReq fileUploadReq) {
        UserDetail user = SecurityUser.getUser();
        ossOperateService.uploadFile(fileUploadReq, user);
        return null;
    }

    @PostMapping("/uploadVideo")
    @Operation(summary = "上传单个视频")
    public Result uploadVideo(@ModelAttribute FileUploadReq fileUploadReq) {
        if (ossOperateService.isVideoByExtension(fileUploadReq.getFile())) {
            UserDetail user = SecurityUser.getUser();
            ossOperateService.uploadFile(fileUploadReq, user);
        }
        return null;
    }
}
